package com.gp.cyg.exception;

import cn.hutool.http.HttpRequest;
import com.gp.cyg.controller.CygController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.RejectedExecutionException;

/**
 * ExceptionHandler
 *
 * @author gsp
 * @date 2022/9/20
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @Autowired
    private CygController cygController;

    @ExceptionHandler(value = Exception.class)
    public HashMap<String, String> Exception(CustomException e) {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("msg", e.getMessage());
        hashMap.put("code", "500");
        return hashMap;
    }

    @ExceptionHandler(value = RejectedExecutionException.class)
    public HashMap<String, String> rejectTask() {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("msg", "当前存在准备执行的任务,goodsCode:" + cygController.goodsCode);
        hashMap.put("code", "500");
        return hashMap;
    }

    @ExceptionHandler(value = CustomException.class)
    public HashMap<String, String> customException(CustomException e) {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("msg", e.getMessage());
        hashMap.put("code", "500");
        return hashMap;
    }


}
